# -*- encoding: utf-8 -*-
import serial
import time
import sys

serial_port = 4
measurment_time = 10
log_range = 20


if sys.platform == 'win32':
    cpu_time = time.clock
else:
    cpu_time = time.time
print "Testing serial port {0} for {1} seconds.".format(serial_port, measurment_time)
s = serial.Serial(serial_port, 115200)
s.read(s.inWaiting())
start = old = cpu_time()
hist = []
for i in range(log_range):
    hist.append(0)
while cpu_time() < start + measurment_time:
    byte = s.read()
    now = cpu_time()
    diff = int(round((now-old)*1000))
    if diff < log_range:
        hist[diff] += 1
    #print repr(diff)
    old = now

print hist
